package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.CstProject;
import com.ruoyi.system.service.ICstProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 项目Controller
 * 
 * @author zjw
 * @date 2023-01-04
 */
@RestController
@RequestMapping("/cst/project")
public class CstProjectController extends BaseController
{
    @Autowired
    private ICstProjectService cstProjectService;

    /**
     * 查询项目列表
     */
    @PreAuthorize("@ss.hasPermi('cst:project:list')")
    @GetMapping("/list")
    public TableDataInfo list(CstProject cstProject)
    {
        startPage();
        List<CstProject> list = cstProjectService.selectCstProjectList(cstProject);
        return getDataTable(list);
    }

    /**
     * 导出项目列表
     */
    @PreAuthorize("@ss.hasPermi('cst:project:export')")
    @Log(title = "项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CstProject cstProject)
    {
        List<CstProject> list = cstProjectService.selectCstProjectList(cstProject);
        ExcelUtil<CstProject> util = new ExcelUtil<CstProject>(CstProject.class);
        util.exportExcel(response, list, "项目数据");
    }

    /**
     * 获取项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('cst:project:query')")
    @GetMapping(value = "/{projectId}")
    public AjaxResult getInfo(@PathVariable("projectId") Long projectId)
    {
        return success(cstProjectService.selectCstProjectByProjectId(projectId));
    }

    /**
     * 新增项目
     */
    @PreAuthorize("@ss.hasPermi('cst:project:add')")
    @Log(title = "项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CstProject cstProject)
    {
        return toAjax(cstProjectService.insertCstProject(cstProject));
    }

    /**
     * 修改项目
     */
    @PreAuthorize("@ss.hasPermi('cst:project:edit')")
    @Log(title = "项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CstProject cstProject)
    {
        return toAjax(cstProjectService.updateCstProject(cstProject));
    }

    /**
     * 删除项目
     */
    @PreAuthorize("@ss.hasPermi('cst:project:remove')")
    @Log(title = "项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{projectIds}")
    public AjaxResult remove(@PathVariable Long[] projectIds)
    {
        return toAjax(cstProjectService.deleteCstProjectByProjectIds(projectIds));
    }
}
